import Vue from 'vue';
import App from './App';
import router from './router';
// 全局使用Element
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use (ElementUI, {
  size: localStorage.getItem ('layoutSize') || 'medium',
}); //使用并设置布局大小
import store from './store'; // 应用vuex

import moment from 'moment'; //时间格式化
import '@/components/publicJs/leadOutExcel/index.js'; //导出excel

// Element中封装的一些方法
import elementUIFun from '@/components/publicJs/elementUIFun.js';
Vue.prototype.$confirm = elementUIFun.$confirm; //确认框

import {openPage} from '@/components/publicJs/utils/vueOpenPage.js';
Vue.prototype.$openPage = openPage; //打开新的页面

import {getParams} from '@/components/publicJs/utils/decodeURIComponent.js';
// 时间格式化
Vue.prototype.$moment = function (value, format) {
  if (!value) {
    return '';
  }
  return moment (Number (value)).format (format || 'YYYY-MM-DD HH:mm');
};

//钉钉权限验证
import {authLogin, ddConfig} from '@/components/auth/dingtalk.js';

Vue.config.productionTip = false;

NewVue ();
async function NewVue () {
  // 获取链接上的一些参数
  const getUrlParamsRes = await getParams (['corpId', 'APPkey']);
  localStorage.setItem ('getUrlParamsRes', JSON.stringify (getUrlParamsRes));

  // 签名 免登
  const [ddConfigRes, authLoginRes] = await Promise.all ([
    ddConfig (),
    authLogin (),
  ]); //同步掉
  if (!ddConfigRes.success) {
    ElementUI.Message.warning (ddConfigRes.errorMsg); //只做提醒
  }
  if (!authLoginRes.success) {
    ElementUI.Message.warning (authLoginRes.errorMsg);
    return;
  }

  new Vue ({
    el: '#app',
    router,
    store,
    components: {
      App,
    },
    template: '<App/>',
  });
}
